
@extends ('layouts/app')

@section('content')
    <div class="weui-pay append">
        <form action="" id="info" name="info">
            @csrf
            <div class="site weui-cells_checkbox">
                <div class="weui-cell ">
                    <div class="weui-cell__hd">
                        <label for="oldPassword">旧密码:</label>
                    </div>
                    <div class="weui-cell__bd">
                        <input type="password"  class="weui-input" name="oldPassword" placeholder="">
                    </div>
                </div>
            </div>
            <div class="site weui-cells_checkbox">
                <div class="weui-cell ">
                    <div class="weui-cell__hd">
                        <label for="newPassword">密码:</label>
                    </div>
                    <div class="weui-cell__bd">
                        <input type="password"  class="weui-input" name="newPassword" placeholder="">
                    </div>
                </div>
            </div>

            <div class="site weui-cells_checkbox">
                <div class="weui-cell ">
                    <div class="weui-cell__hd">
                        <label for="cnewPassword">确认密码:</label>
                    </div>
                    <div class="weui-cell__bd">
                        <input type="password"  class="weui-input" name="cnewPassword" placeholder="">
                    </div>

                </div>
            </div>
            <div class="demos-content-padded">
                <a href="javascript:;" class="weui-btn weui-btn_blue open-popup">确认</a>
            </div>
        </form>
    </div>
    <script>

        // 点击确认
        $(".open-popup").click(function () {
            var newPassword = $("input[name='newPassword']").val(),
                cnewPassword = $("input[name='cnewPassword']").val(),
                oldPassword = $("input[name='oldPassword']").val();

                console.log("newPassword", newPassword);
            var info = InputStrategy.check("isNumber", newPassword);

            if (info) {
                return $.toast(info, "text");
            }

            if (newPassword !== newPassword) {
                return $.toast("两次输入的密码不一致！", "text");
            }

            save("/api/user/updatepassword", "#info", function (res) {
                if (typeof res === 'string') {
                    res = JSON.parse(res);
                }

                $.alert(res.info, function () {
                    if (res.code == 200) {
                        $.get("/logout", {}, function (res) {
                            Storage.remove("userInfo");
                            location.href = "/login";
                        });
                    }
                });
            });
        });

//        修改密码
//        /api/user/updatepassword
//        参数： oldPassword   旧密码
//        newPassword   新密码
//        cnewPassword   新密码
    </script>
@endsection
